package com.example.controller;

import com.example.common.Result;
import com.example.entity.Table;
import com.example.service.TableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Table)表控制层
 *
 * @author makejava
 * @since 2024-06-11 19:14:58
 */
@RestController
@RequestMapping("table")
@Api(tags = "桌位模块")
public class TableController {
    /**
     * 服务对象
     */
    @Resource
    private TableService tableService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("根据主键查询桌位")
    public Result<Table> queryById(@PathVariable("id") Integer id) {
        return Result.success(this.tableService.queryById(id));
    }

    @GetMapping
    @ApiOperation("查询所有空闲桌位")
    public Result<List<Table>> queryFreeAll(){
        List<Table> all = this.tableService.queryFreeAll();
        return Result.success(all);
    }

    @PutMapping("/update")
    @ApiOperation("根据桌位id修改桌位信息")
    public Result<Table> updateById(@RequestBody Table table) {
        Table t = this.tableService.update(table);
        return Result.success(t);
    }

}

